"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.set = void 0;

/**
 * 设定数据
 * @param target 目标
 * @param path 路径
 * @param value 目标值
 * ```js
 * let obj = {};
 * set(obj, 'a.b.c', 1);
 * // obj.a.b.c -> 1
 * ```
 */
var set = function set(target, path, value) {
  var travel = function travel(regexp) {
    return String.prototype.split.call(path, regexp).filter(Boolean).reduce(function (res, key, index, arr) {
      if (res === null || res === undefined) {
        res = {};
      }

      if (arr.length === index + 1) {
        res[key] = value;
      } else {
        res[key] = {};
      }

      return res[key];
    }, target);
  };

  var result = travel(/[,[\].]+?/);
  return Boolean(result);
};

exports.set = set;